<?php
 
// no direct access
defined('_JEXEC') or die('Restricted access');

// import application view
jimport('joomla.application.component.view');

class SyncrViewSite extends JView
{
	public function display($tpl = null)
	{
		$app 	=& JFactory::getApplication();
		$db		=& JFactory::getDBO();
		$user 	=& JFactory::getUser();
		$model	=& $this->getModel();
		
		// load data for site
		$site =& $this->get('data');
		$isNew = ($site->id < 1);
		
		if ($model->isCheckedOut( $user->get('id') )) {
			$msg = JText::sprintf( 'DESCBEINGEDITTED', JText::_( 'THE_SITE' ), $site->name );
			$app->redirect( 'index.php?option=com_syncr&controller=sites', $msg );
		}
		
		if ($isNew) {
		 	$site->name			= "";
			$site->color		= "";
			$site->logo			= "";
			$site->apikey		= "";
			$site->image		= 0;
			$site->published	= 0;
		}		
		
		// image radio
		$image = JHTML::_('select.booleanlist', 'image', 'class="input"', $site->image);
		// published radio
		$published = JHTML::_('select.booleanlist', 'published', 'class="input"', $site->published);
		
		// assign references
		$this->assignRef('site', $site);
		$this->assign('published', $published);
		$this->assign('image', $image);
		
		// set toolbar
		$this->_setToolBar();
		
		// call parent behavior with template
		parent::display($tpl);
	}
	
	private function _setToolBar() {
		JToolBarHelper::title(JText::_('SYNCR_SITE'), 'generic.png');
		JToolBarHelper::apply();
		JToolBarHelper::save();
		JToolBarHelper::cancel();
	}
}